package com.yonyou.pmclouds.businessobject.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.billtype.rmiitf.BillTypeQuery;
import com.yonyou.pmclouds.businessobject.entity.BusinessObjectVO;
import com.yonyou.pmclouds.businessobject.rmiitf.BusinessObjectMaintain;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 云打印业务对象管理
 *
 * @author zhangzhonghao
 */

@Slf4j
@RestController
@RequestMapping({"/bo"})
public class BusinessObjectController {

    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private BusinessObjectMaintain businessObjectMaintain;

    /**
     * 业务对象初始化，租户ID为null即为系统业务对象，否为租户业务对象
     *
     * @return 初始化结果
     * @throws BusinessException
     */
    @PostMapping("/init")
    public String init(@RequestParam(value = "tenantId", required = false) String tenantId) throws BusinessException {
        return businessObjectMaintain.initBO(tenantId);
    }

    @PostMapping("/save")
    public String saveBO(@RequestBody BusinessObjectVO businessObjectVO,
                         @RequestParam(value = "tenantId", required = false) String tenantId) throws BusinessException {
        return businessObjectMaintain.saveBo(businessObjectVO, tenantId);
    }

    @GetMapping("/getPrintCode")
    public String getPrintCodeByBO(@RequestParam("boCode") String boCode,
                                   @RequestParam("tenantId") String tenantId) throws BusinessException {
        return businessObjectMaintain.getPrintCode(boCode, tenantId);
    }

    @GetMapping("/getPrintCodeByType")
    public String getPrintCodeByType(@RequestParam("billType") String billType,
                                     @RequestParam("tenantId") String tenantId,
                                     @RequestParam(name = "pkProcess", required = false) String pkProcess) throws BusinessException {
        return businessObjectMaintain.getPrintCodeByType(tenantId, billType, pkProcess);
    }

    @RequestMapping("/initTenantBizz")
    public String initTenantBizz(@RequestBody List<String> tenantIdList) throws BusinessException {
        return businessObjectMaintain.initTenantBizz(tenantIdList);
    }

}
